package com.hd123.rumba.gwt.widget.client;

import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.HorizontalPanel;

public class DoubleLabeledDateBox extends HorizontalPanel {

  private LabeledDateBox dateBoxFrom, dateBoxTo;

  private String captionFrom, captionTo;

  private boolean required = false;

  private boolean readOnly = false;

  public DoubleLabeledDateBox() {
    this("", "");
  }

  public DoubleLabeledDateBox(String captionFrom, String captionTo) {
    this.captionFrom = captionFrom;
    this.captionTo = captionTo;

    this.setSpacing(4);

    dateBoxFrom = new LabeledDateBox(captionFrom);
    dateBoxTo = new LabeledDateBox(captionTo);

    this.add(dateBoxFrom);
    this.add(dateBoxTo);
  }

  public void setLabelFromWidth(String width) {
    this.getDateBoxFrom().getLabel().setWidth(width);
  }

  public void setLabelToWidth(String width) {
    this.getDateBoxTo().getLabel().setWidth(width);
  }

  public void setDateTextFrom(String date) {
    this.dateBoxFrom.setDateText(date);
  }

  public String getDateTextFrom() {
    return this.dateBoxFrom.getDateText();
  }

  public String getDateTextTo() {
    return this.dateBoxTo.getDateText();
  }

  public void setDateTextTo(String date) {
    this.dateBoxTo.setDateText(date);
  }

  public void addChangeListener(ChangeListener listener) {
    dateBoxFrom.addChangeListener(listener);
    dateBoxTo.addChangeListener(listener);
  }

  public void removeChangeListener(ChangeListener listener) {
    dateBoxFrom.removeChangeListener(listener);
    dateBoxTo.addChangeListener(listener);
  }

  public LabeledDateBox getDateBoxFrom() {
    return dateBoxFrom;
  }

  public void setDateBoxFrom(LabeledDateBox dateBoxFrom) {
    this.dateBoxFrom = dateBoxFrom;
  }

  public LabeledDateBox getDateBoxTo() {
    return dateBoxTo;
  }

  public void setDateBoxTo(LabeledDateBox dateBoxTo) {
    this.dateBoxTo = dateBoxTo;
  }

  public String getCaptionFrom() {
    return captionFrom;
  }

  public void setCaptionFrom(String captionFrom) {
    this.captionFrom = captionFrom;
  }

  public String getCaptionTo() {
    return captionTo;
  }

  public void setCaptionTo(String captionTo) {
    this.captionTo = captionTo;
  }

  public boolean isRequired() {
    return required;
  }

  public void setRequired(boolean required) {
    this.required = required;
    this.dateBoxFrom.setRequired(this.required);
    this.dateBoxTo.setRequired(this.required);
  }

  public boolean isReadOnly() {
    return readOnly;
  }

  public void setReadOnly(boolean readOnly) {
    this.readOnly = readOnly;
    this.dateBoxFrom.setReadOnly(this.readOnly);
    this.dateBoxTo.setReadOnly(this.readOnly);
  }

}
